/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
 * Description: 
 * Author: g00421808
 * Create: 11/17/2022
 * Notes: 
 */

#ifndef JSBIND_CALLBACK_H
#define JSBIND_CALLBACK_H

#include <node_api.h>
#include "jsbind/config.h"

namespace Jsb {
template<typename T>
class Callback;

template<typename R, typename... P>
class Callback<R (P...)> {
public:
    explicit Callback(const napi_env env, const napi_value cb)
        : env_(env), cb_(cb) {}

    R operator() (P... args) const {
        return(Call(std::move(args)...));
    }

    R Call(P&&... args) const;

    R CallMethod(napi_env env, napi_value target, P... args) const;

protected:
    napi_env env_;

    napi_value cb_;
};
} // namespace Jsb
#endif //JSBIND_CALLBACK_H
